// DlgTaskListEdit.cpp : implementation file
//

#include "stdafx.h"
#include "mxgtd.h"
#include "DlgTaskListEdit.h"
#include "afxdialogex.h"
#include "DlgTaskPropEdit.h"
#include "../core/GtdDOMItem.h"
#include "TaskEntryListTreeItem.h"

// CDlgTaskListEdit dialog
//EASYSIZE(control,left,top,right,bottom,options)
BEGIN_EASYSIZE_MAP(CDlgTaskListEdit)
	EASYSIZE(IDC_TREE_TASK,ES_BORDER,ES_BORDER,ES_BORDER,ES_BORDER,0)
	EASYSIZE(IDOK,ES_KEEPSIZE,ES_KEEPSIZE,ES_BORDER,ES_BORDER,0)
	EASYSIZE(IDCANCEL,ES_KEEPSIZE,ES_KEEPSIZE,ES_BORDER,ES_BORDER,0)
	EASYSIZE(IDC_BUTTON_ADDTASK,ES_BORDER,ES_KEEPSIZE,ES_KEEPSIZE,ES_BORDER,0)
	EASYSIZE(IDC_BUTTON_DELTASK,ES_BORDER,ES_KEEPSIZE,ES_KEEPSIZE,ES_BORDER,0)
END_EASYSIZE_MAP


IMPLEMENT_DYNAMIC(CDlgTaskListEdit, CDialogEx)

CDlgTaskListEdit::CDlgTaskListEdit(CWnd* pParent /*=NULL*/)
	: CDialogEx(CDlgTaskListEdit::IDD, pParent)
{

}

CDlgTaskListEdit::~CDlgTaskListEdit()
{
}

void CDlgTaskListEdit::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_TREE_TASK, m_tasklistTree);
}


BEGIN_MESSAGE_MAP(CDlgTaskListEdit, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON_ADDTASK, &CDlgTaskListEdit::OnBnClickedButtonAddtask)
	ON_BN_CLICKED(IDOK, &CDlgTaskListEdit::OnBnClickedOk)
	ON_WM_SIZE()
	ON_WM_ERASEBKGND()	
END_MESSAGE_MAP()


// CDlgTaskListEdit message handlers


void CDlgTaskListEdit::OnBnClickedButtonAddtask()
{
	// TODO: Add your control notification handler code here
	GtdTaskEntry* pEntry = theApp.getGTDDOM().allocateDOMItem<GtdTaskEntry>();
	CDlgTaskPropEdit editProp(pEntry,this);
	if(IDOK == editProp.DoModal())
	{		
		theApp.getGTDDOM().AddTaskEntry(pEntry);
		TaskEntryListTreeItem root = TaskEntryListTreeItem::GetRoot(m_tasklistTree);
		root.AddTaskEntryItem(pEntry);
	}
	
}


void CDlgTaskListEdit::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	CDialogEx::OnOK();
}


void CDlgTaskListEdit::OnSize(UINT nType, int cx, int cy)
{
	CDialogEx::OnSize(nType, cx, cy);

	// TODO: Add your message handler code here
	UPDATE_EASYSIZE;
}


BOOL CDlgTaskListEdit::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  Add extra initialization here
	m_tasklistTree.Init();
	m_tasklistTree.SetNormalImageList(IDB_BITMAP_NORMAL);
	m_tasklistTree.SetStateImageList(IDB_BITMAP_STATE);
	TaskEntryListTreeItem::LoadTree(m_tasklistTree);


	INIT_EASYSIZE;

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}


BOOL CDlgTaskListEdit::OnEraseBkgnd(CDC* pDC)
{
	// TODO: Add your message handler code here and/or call default
	//return TRUE;
	return CDialogEx::OnEraseBkgnd(pDC);
}

